var t = require("../../../api.js"), a = getApp();

Page({
    data: {
        money: 0,
        balance: 0,
        alipay: "",
        name: "",
        account: "",
        yue: 0,
        distribution: ""
    },
    onLoad: function(t) {
        console.log(t), this.setData({
            type: t.type,
            yue: t.yue,
            distribution: t.distribution
        });
    },
    onShow: function() {
        var e = this;
        a.request({
            url: t.bank.get_maxmoney,
            method: "post",
            data: {
                type: 1,
                default: 1
            },
            state: 1,
            success: function(t) {
                console.log(t), 1 == t.code && e.setData({
                    data: t.data,
                    balance: t.data.price
                });
            }
        });
    },
    get_alipay: function(t) {
        console.log(t.detail.value), this.setData({
            alipay: t.detail.value
        });
    },
    get_name: function(t) {
        this.setData({
            name: t.detail.value
        });
    },
    get_account: function(t) {
        this.setData({
            money: t.detail.value
        });
    },
    sendRequest: function() {
        var e = this, o = this.data, n = o.money, i = o.alipay, s = o.account, c = o.balance, u = o.name;
        if (console.log(n, i, s), "" == i) return wx.showToast({
            title: "支付宝账号不得为空",
            icon: "none",
            mask: !0
        }), !1;
        if ("" == u) return wx.showToast({
            title: "请填写用户名",
            icon: "none",
            mask: !0
        }), !1;
        if ("" == n) return wx.showToast({
            title: "请填写正确金额",
            icon: "none",
            mask: !0
        }), !1;
        if (n < 1) return wx.showToast({
            title: "提现金额至少1元",
            icon: "none",
            mask: !0
        }), !1;
        if (Number(n) > Number(e.data.balance)) return wx.showToast({
            title: "金额大于可提现金额",
            icon: "none",
            mask: !0
        }), !1;
        console.log(n, c, s), wx.showLoading({
            mask: !0
        });
        e.data.type;
        1 == this.data.distribution ? a.request({
            url: t.user.apply,
            method: "post",
            data: {
                price: n,
                alipay: i,
                nickname: u,
                type: 2
            },
            success: function(t) {
                console.log("提现申请结果", t), wx.hideLoading(), 1 == t.code ? (wx.showToast({
                    title: t.msg,
                    icon: "none",
                    mask: !0,
                    duration: 2e3
                }), setTimeout(function() {
                    wx.navigateBack({
                        delta: 1
                    });
                }, 2e3)) : wx.showToast({
                    title: t.msg,
                    icon: "none",
                    mask: !0
                });
            }
        }) : 2 == this.data.distribution && a.request({
            url: t.distribution.apply,
            method: "post",
            data: {
                price: n,
                alipay: i,
                nickname: u,
                type: 2
            },
            success: function(t) {
                console.log("提现申请结果", t), wx.hideLoading(), 1 == t.code ? (wx.showToast({
                    title: t.msg,
                    icon: "none",
                    mask: !0,
                    duration: 2e3
                }), setTimeout(function() {
                    wx.navigateBack({
                        delta: 1
                    });
                }, 2e3)) : wx.showToast({
                    title: t.msg,
                    icon: "none",
                    mask: !0
                });
            }
        });
    }
});